@@ -37,7 +37,7 @@ |
||
37 | 37 |
<ConfirmationsSetting value="0" id="Add" /> |
38 | 38 |
<ConfirmationsSetting value="0" id="Remove" /> |
39 | 39 |
</component> |
40 |
- <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK"> |
|
40 |
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="JDK" project-jdk-type="JavaSDK"> |
|
41 | 41 |
<output url="file://$PROJECT_DIR$/build/classes" /> |
42 | 42 |
</component> |
43 | 43 |
<component name="ProjectType"> |
@@ -42,6 +42,9 @@ public class CameraService extends Service { |
||
42 | 42 |
private static final String MSG_TYPE_NOT_INIT = "not init"; //需要初始化 |
43 | 43 |
private static final String MSG_TYPE_TIME_OUT = "time out"; //继续调用waitforevent |
44 | 44 |
|
45 |
+ private static final int MAX_NO_PHOTO_COUNT = 500; |
|
46 |
+ private int count = 0; |
|
47 |
+ |
|
45 | 48 |
@Override |
46 | 49 |
public IBinder onBind(Intent intent) { |
47 | 50 |
return null; |
@@ -49,17 +52,22 @@ public class CameraService extends Service { |
||
49 | 52 |
|
50 | 53 |
@Override |
51 | 54 |
public int onStartCommand(Intent intent, int flags, int startId) { |
55 |
+ LogHelper.d("czy","CameraService onStartCommand "); |
|
52 | 56 |
if(intent!=null&&intent.getIntExtra(EXTRA_CMD,0)>0){ |
53 | 57 |
int cmd = intent.getIntExtra(EXTRA_CMD,0); |
54 | 58 |
if(cmd == CMD_EXIT_CAMERA_CONNECTION){ |
59 |
+ LogHelper.d("czy","CameraService 收到停止进程任务"); |
|
55 | 60 |
stopCameraService(); |
56 | 61 |
}else if(cmd == CMD_INIT_CAMERA_CONNECTION){ |
57 | 62 |
if(!isInitExecuted){ |
63 |
+ LogHelper.d("czy","CameraService 收到重启进程任务"); |
|
64 |
+ count = 0; |
|
58 | 65 |
cameraInitTask = new CameraInitTask(); |
59 | 66 |
cameraInitTask.execute(); |
60 | 67 |
} |
61 | 68 |
}else if(cmd == CMD_START_CAPTURE_PHOTO){ |
62 | 69 |
if(isInitExecuted){ |
70 |
+ LogHelper.d("czy","CameraService 收到开始拍摄任务"); |
|
63 | 71 |
sessionWorkingDirPath = intent.getStringExtra(EXTRA_SESSION_DIR); |
64 | 72 |
if(!TextUtils.isEmpty(sessionWorkingDirPath)){ |
65 | 73 |
startCapture(); |
@@ -76,6 +84,8 @@ public class CameraService extends Service { |
||
76 | 84 |
} |
77 | 85 |
|
78 | 86 |
private void stopCameraService(){ |
87 |
+ count = 0; |
|
88 |
+ LogHelper.d("czy","CameraService stopCameraService "); |
|
79 | 89 |
if(cameraInitTask!=null){ |
80 | 90 |
cameraInitTask.cancel(); |
81 | 91 |
} |
@@ -99,6 +109,7 @@ public class CameraService extends Service { |
||
99 | 109 |
|
100 | 110 |
@Override |
101 | 111 |
protected Integer doInBackground(Void... params) { |
112 |
+ LogHelper.d("czy","CameraService CameraInitTask "); |
|
102 | 113 |
isInitExecuted = true; |
103 | 114 |
return CameraJNIInterface.getInstance().java_mygpcamerainit(); |
104 | 115 |
} |
@@ -110,10 +121,12 @@ public class CameraService extends Service { |
||
110 | 121 |
return; |
111 | 122 |
} |
112 | 123 |
if(result>=0){ |
124 |
+ LogHelper.d("czy","CameraService 相机初始化成功"); |
|
113 | 125 |
Bundle bundle = new Bundle(); |
114 | 126 |
bundle.putInt(EXTRA_STATUS_PART,MSG_CAMERA_INIT_SUCCESS); |
115 | 127 |
sendCameraIntent(bundle); |
116 | 128 |
}else{ |
129 |
+ LogHelper.d("czy","CameraService 相机初始化失败,杀掉进程"); |
|
117 | 130 |
Bundle bundle = new Bundle(); |
118 | 131 |
bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR); |
119 | 132 |
sendCameraIntent(bundle); |
@@ -147,15 +160,17 @@ public class CameraService extends Service { |
||
147 | 160 |
|
148 | 161 |
private void fetchPhotoTask(){ |
149 | 162 |
if(!isLastQueryReturned){ |
150 |
- LogHelper.d("czy","fetchPhotoTask last query not finished,return "); |
|
163 |
+ LogHelper.d("czy","CameraService fetchPhotoTask last query not finished,return "); |
|
151 | 164 |
return; |
152 | 165 |
} |
153 | 166 |
|
154 | 167 |
isLastQueryReturned = false; |
155 | 168 |
String eventMsg = CameraJNIInterface.getInstance().java_mygpcamerawaitforevent(sessionWorkingDirPath); |
156 |
- LogHelper.d("czy","mygpcamerawaitforevent return result = "+eventMsg); |
|
169 |
+ LogHelper.d("czy","CameraService mygpcamerawaitforevent return result = "+eventMsg); |
|
157 | 170 |
if(eventMsg!=null && eventMsg.length()>0){ |
171 |
+ count = 0; |
|
158 | 172 |
if(MSG_TYPE_NOT_INIT.equalsIgnoreCase(eventMsg)||MSG_TYPE_CAMERA_ERROR.equalsIgnoreCase(eventMsg)){ |
173 |
+ LogHelper.d("czy","CameraService fetchPhotoTask 相机连接错误,重新连接试试"); |
|
159 | 174 |
Bundle bundle = new Bundle(); |
160 | 175 |
bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR); |
161 | 176 |
sendCameraIntent(bundle); |
@@ -165,13 +180,22 @@ public class CameraService extends Service { |
||
165 | 180 |
}else{ |
166 | 181 |
String sub = eventMsg.substring(0,1); |
167 | 182 |
if(TextUtils.isDigitsOnly(sub)){ |
168 |
- LogHelper.d("czy","fetchPhotoTask new photo found"); |
|
183 |
+ LogHelper.d("czy","CameraService fetchPhotoTask new photo found"); |
|
169 | 184 |
Bundle bundle = new Bundle(); |
170 | 185 |
bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_NEW_PHOTO_FOUND); |
171 | 186 |
bundle.putString(EXTRA_DATA_PART,eventMsg); |
172 | 187 |
sendCameraIntent(bundle); |
173 | 188 |
} |
174 | 189 |
} |
190 |
+ }else{ |
|
191 |
+ count++; |
|
192 |
+ if(count>=MAX_NO_PHOTO_COUNT){ |
|
193 |
+ LogHelper.d("czy","CameraService fetchPhotoTask 太久没发现新照片了,重新连接试试"); |
|
194 |
+ Bundle bundle = new Bundle(); |
|
195 |
+ bundle.putInt(EXTRA_STATUS_PART, MSG_CAMERA_CONN_ERROR); |
|
196 |
+ sendCameraIntent(bundle); |
|
197 |
+ stopCameraService(); |
|
198 |
+ } |
|
175 | 199 |
} |
176 | 200 |
|
177 | 201 |
isLastQueryReturned = true; |
@@ -24,6 +24,7 @@ import static ai.pai.lensman.dslr.CameraService.CMD_INIT_CAMERA_CONNECTION; |
||
24 | 24 |
import static ai.pai.lensman.dslr.CameraService.CMD_START_CAPTURE_PHOTO; |
25 | 25 |
import static ai.pai.lensman.dslr.CameraService.EXTRA_CMD; |
26 | 26 |
import static ai.pai.lensman.dslr.CameraService.EXTRA_DATA_PART; |
27 |
+import static ai.pai.lensman.dslr.CameraService.EXTRA_SESSION_DIR; |
|
27 | 28 |
import static ai.pai.lensman.dslr.CameraService.EXTRA_STATUS_PART; |
28 | 29 |
import static ai.pai.lensman.dslr.CameraService.MSG_CAMERA_CONN_ERROR; |
29 | 30 |
import static ai.pai.lensman.dslr.CameraService.MSG_CAMERA_INIT_SUCCESS; |
@@ -79,6 +80,7 @@ public class SessionInteractor implements Callback{ |
||
79 | 80 |
public void startCapture() { |
80 | 81 |
Intent intent = new Intent(App.getAppContext(), CameraService.class); |
81 | 82 |
intent.putExtra(EXTRA_CMD,CMD_START_CAPTURE_PHOTO); |
83 |
+ intent.putExtra(EXTRA_SESSION_DIR,sessionWorkingDirPath); |
|
82 | 84 |
App.getAppContext().startService(intent); |
83 | 85 |
} |
84 | 86 |
|
@@ -91,7 +93,12 @@ public class SessionInteractor implements Callback{ |
||
91 | 93 |
Intent intent = new Intent(App.getAppContext(), CameraService.class); |
92 | 94 |
intent.putExtra(EXTRA_CMD,CMD_EXIT_CAMERA_CONNECTION); |
93 | 95 |
App.getAppContext().startService(intent); |
94 |
- App.getAppContext().unregisterReceiver(cameraReceiver); |
|
96 |
+ try{ |
|
97 |
+ App.getAppContext().unregisterReceiver(cameraReceiver); |
|
98 |
+ }catch (Exception e){ |
|
99 |
+ e.printStackTrace(); |
|
100 |
+ } |
|
101 |
+ |
|
95 | 102 |
LogHelper.d("czy","endSession "); |
96 | 103 |
listener.onSessionEnd(sessionBean.sessionId); |
97 | 104 |
} |